import { Controller, Get, Req } from '@nestjs/common';
import { HomeService } from './home.service';
import * as requestIp from 'request-ip';
import { Request } from 'express'; // 添加这一行
@Controller('home')
export class HomeController {
  constructor(private readonly homeService: HomeService) {}

  // 保存访问ip
  @Get('save/ip')
  saveAccessIp(@Req() req: Request) {
    const clientIp = requestIp.getClientIp(req); // 使用 request-ip 获取 IP
    console.log(clientIp);
    return this.homeService.saveAccessIp(clientIp);
  }
  // 获取访问ip
  @Get('ip')
  getAccessIp() {
    return this.homeService.getAccessIp();
  }
  // 获取访问ip数量
  @Get('ip/count')
  getAccessIpCount() {
    return this.homeService.getAccessIpCount();
  }
  // 发送服务器信息/数据库信息/内存信息/CPU信息/时间信息
  @Get('')
  sendServerInfo() {
    return this.homeService.getServerInfo();
  }
}
